package DemoText;

/**
 * 两两交换链表中的节点(递归)
 */
public class LeetCode24 {
    static class ListNode {
        int val;
        ListNode next;
        ListNode () {}

        public ListNode(int val) {
            this.val = val;
        }

        public ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
    public ListNode swapPairs(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode newHead = swapPairs(head.next.next);
        ListNode ret = head.next;
        head.next.next = head;
        head.next = newHead;
        return ret;
    }
}
